package com.yang.config;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author: 杨庆
 * @since: 2022.9.8 16:27
 * @description:
 */
public class MarketSession extends DefaultWebSessionManager {
    public static final String MARKET_ADMIN_TOKEN="X-CskaoyanMarket-Admin-Token";
    public static final String MARKET_ADMIN_WX_TOKEN="X-CskaoyanMarket-Token";
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String sessionId1 =httpServletRequest.getHeader(MARKET_ADMIN_TOKEN);
        if (StringUtils.isEmpty(sessionId1)) {
            return sessionId1;
        }
        String sessionId2 =httpServletRequest.getHeader(MARKET_ADMIN_WX_TOKEN);
        if (StringUtils.isEmpty(sessionId2)) {
            return sessionId2;
        }

        return super.getSessionId(request, response);
    }
}
